package fi.solita.dojo.mazeserver.game.internal

import fi.solita.dojo.mazeserver.map._
import scala.collection._

final case class GameLocation (passable: Boolean, hole: Boolean, point: Boolean, coordinates: Coordinates) {

//	lazy val coordinates: Coordinates = GameWorld.locationOf(this)
//	def coordinates = GameWorld.locationOf(this)

	override def toString(): String = coordinates toString
    
	def name: String = coordinates.toString 

	def neighbour(direction: Directions.Direction): GameLocation =
	  GameWorld.map()(coordinates.neighbour(direction))

	def passable(direction: Directions.Direction): Boolean = 
      GameWorld.map().get(coordinates.neighbour(direction)) match {
        case Some(d) => d.passable
        case None => false
      }
 
	def legalMove(direction: Directions.Direction): Boolean = {
		GameWorld.map.get(coordinates.neighbour(direction)) match {
		case Some(loc) => {
			loc.passable
		}
		case None => false
		}
	}
}

object GameLocation {
  
	def wall(c: Coordinates) = GameLocation(false, false, false, c)
	def hole(c: Coordinates) = GameLocation(true, true, false, c)
	def corridor(c: Coordinates) = GameLocation(true, false, false, c)
	def point(c: Coordinates) = GameLocation(true, false, true, c)

}